package jianzhiOfferII;
//剑指 Offer II 075. 数组相对排序
public class Num075_relativeSortArray {
    public int[] relativeSortArray(int[] arr1, int[] arr2) {
        int upper = 0;
        for (int i : arr1){
            upper = Math.max(upper , i);
        }
        int []data = new int[upper + 1];
        for (int i : arr1){
            data[i]++;
        }
        int[]res = new int[arr1.length];
        int index = 0;
        for (int i : arr2){
            for (int j = 0; j < data[i]; j++) {
                res[index++] = i;
            }
            data[i] = 0;
        }
        for (int x = 0 ; x <= upper ;x++){
            for (int i = 0; i < data[x]; i++) {
                res[index++] = x;
            }
        }
        return res;

    }
}
